package notes.java.thread;

/**
 * 死锁示例
 * cmd>jsp -v查看所有进程
 * cmd>jstack 1744 加进程号查看
 * @author wangcs
 *
 */
public class DeadLock {
    public static void main(String[] args) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (A.class){
                    System.out.println(Thread.currentThread().getName()+"持有了A类锁");
                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    synchronized (B.class){
                        System.out.println(Thread.currentThread().getName()+"持有了B类锁");
                    }
                }
            }
        }).start();
 
        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (B.class){
                    System.out.println(Thread.currentThread().getName()+"持有了B锁");
                    synchronized (A.class){   System.out.println(Thread.currentThread().getName()+"持有了A锁");}
                }
            }
        }).start();
    }
}
 
class A{}
class B{}
